package kr.hkit.powerjava.chapter17.work;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;

import javax.swing.SwingConstants;
import javax.swing.BoxLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridLayout;
import javax.swing.border.LineBorder;
import java.awt.Color;

public class LableTest01 extends JPanel implements ActionListener {
	private JLabel lbl;
	private JButton btn;
	private JPanel panel;
	/**
	 * Create the panel.
	 */
	public LableTest01() {

		initialize();
	}
	private void initialize() {
		setBorder(new LineBorder(new Color(0, 0, 0)));
		setLayout(new BorderLayout(0, 0));
		btn = new JButton("이미지레이블");
		btn.addActionListener(this);
		btn.setVerticalAlignment(SwingConstants.BOTTOM);
		add(btn, BorderLayout.SOUTH);
		
		panel = new JPanel();
		add(panel, BorderLayout.CENTER);
		panel.setLayout(new GridLayout(0, 1, 0, 0));
		
		lbl = new JLabel("이미지를 보려면 아래버튼을 누르세요");
		panel.add(lbl);
		lbl.setVerticalAlignment(SwingConstants.BOTTOM);
		lbl.setHorizontalAlignment(SwingConstants.CENTER);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(lbl.getIcon() == null){
			ImageIcon img = new ImageIcon("kimtaehee.jpg");
			lbl.setIcon(img);
			lbl.setText(null);
		}else{
			lbl.setIcon(null);
			lbl.setText("이미지를 보려면 버튼을 누르세요");
		}
		
	}
}
